﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Rail.Start.Viewer
{
    public partial class ProjectFoundForm : XtraForm
    {
        public ProjectFoundForm()
        {
            InitializeComponent();
            SetComboBoxProjectid();
        }
        public System.Windows.Forms.ComboBox ComboBoxProjectid
        {
            get
            {
                return this.m_ComboBoxProjectid;
            }
        }
        public SimpleButton SubmitButtonProjectFound
        {
            get
            {
                return this.m_SubmitButtonProjectFound;
            }
        }
        /// <summary>
        /// 存放不存在工程的项目 id及name
        /// </summary>
        public Dictionary<object, object> m_Pairs = new Dictionary<object, object>();

        public void SetComboBoxProjectid()
        {
            //项目表 id及name  列获取
            #region
            string project = "buss_project";
            string sql = Commons.MySqlHelper.GetAllField(project);
            DataTable dataTable_pro = Commons.MySqlHelper.GetDataTable(sql, project);
            object[] items_pro_id = (from DataRow dr in dataTable_pro.Rows select dr[0]).ToArray();
            object[] items_pro_name = (from DataRow dr in dataTable_pro.Rows select dr[2]).ToArray();
            #endregion
            //工程表 id 列获取
            #region
            string engineer = "sys_project_engineering";
            string sql1 = Commons.MySqlHelper.GetAllField(engineer);
            DataTable dataTable_eng = Commons.MySqlHelper.GetDataTable(sql1, engineer);
            object[] items_eng_id = (from DataRow dr in dataTable_eng.Rows select dr[0]).ToArray();
            #endregion
            //将不存在工程的项目 id及name 提取
            #region
            List<object> newitems_pro_name = new List<object>();
            Dictionary<object, object> keyValue_pro = new Dictionary<object, object>();
            for(int i=0;i<items_pro_id.Length;i++)
            {
                if (!items_eng_id.Contains(items_pro_id[i]))
                {
                    newitems_pro_name.Add(items_pro_name[i]);
                    keyValue_pro.Add(items_pro_name[i], items_pro_id[i]);
                }
            }
            items_pro_name = new object[newitems_pro_name.Count];
            newitems_pro_name.CopyTo(items_pro_name);
            #endregion
            m_Pairs.Clear();
            m_Pairs = keyValue_pro;
            ComboBoxProjectid.Items.Clear();
            ComboBoxProjectid.Items.AddRange(items_pro_name);
        }

    }
}
